import socket from "@/socket/UserChatSocket";
import {
    UserStatusChangeHandler,
    AcceptInviteHandler,
    chatMessageHandler,
    InviteFriendHandler,
    ChangeStatusHandler,
    QuitGameHandler,
    OutCardHandler,
    GameOverHandler,
    DoubleHandler
} from "./iofunc";
import { ClientSocketEventType } from "@/share/commonType";

export function socketlistenEvent() {
    socket.on('msg', (msg) => {
        if (msg) {
            let { action, data } = msg
            switch (action) {
                case ClientSocketEventType.UserStatusChange:
                    UserStatusChangeHandler(data)
                    break;
                case ClientSocketEventType.ChatMessage:
                    chatMessageHandler(data)
                    break;
                case ClientSocketEventType.InviteFriend:
                    InviteFriendHandler(data)
                    break;
                case ClientSocketEventType.AcceptInvite:
                    AcceptInviteHandler(data)
                    break;
                case ClientSocketEventType.ChangeStatus:
                    ChangeStatusHandler(data)
                    break;
                case ClientSocketEventType.Double:
                    DoubleHandler(data)
                    break;
                case ClientSocketEventType.OutCard:
                    OutCardHandler(data)
                    break;
                case ClientSocketEventType.QuitGame:
                    QuitGameHandler(data)
                    break;
                case ClientSocketEventType.GameOver:
                    GameOverHandler(data)
                    break;
                default:
                    break;
            }
        }
    })

}

